//
//  XCInTheRankWebViewController.m
//  SoundOfNature
//
//  Created by 梁新昌 on 16/3/15.
//  Copyright © 2016年 梁新昌. All rights reserved.
//

#import "XCInTheRankWebViewController.h"

@interface XCInTheRankWebViewController ()<UIWebViewDelegate>
@property (nonatomic, retain) UIActivityIndicatorView *action;
@property (nonatomic, copy) NSString *link;
@property (nonatomic, copy) NSString *navigationName;
@end

@implementation XCInTheRankWebViewController
- (instancetype)initWithLink:(NSString *)link WithNavigationName:(NSString *) name
{
    self = [super init];
    if (self) {
        self.link = link;
        self.navigationName = name;
    }
    return self;
}
- (void)dealloc {
    [_action release];
    [_navigationName release];
    [_link release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.link]];
    self.webView.delegate = self;
    [self.webView loadRequest:request];
    [self.view addSubview:self.webView];
    [_webView release];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"Image-leftBarButton"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemAction)];
}
//  webView
- (void)webViewDidStartLoad:(UIWebView *)webView {
    UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
    [view setTag:1000];
    [view setBackgroundColor:[UIColor colorWithRed:0.400 green:1.000 blue:1.000 alpha:1.000]];
    view.alpha = 0.5;
    self.action = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [self.action setCenter:view.center];
    [self.action setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
    [self.view addSubview:view];
    [view addSubview:self.action];
    [self.action startAnimating];
    [view release];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [self.action stopAnimating];
    UIView *view = (UIView *)[self.view viewWithTag:1000];
    [view removeFromSuperview];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)leftBarButtonItemAction {
    [self.navigationController popViewControllerAnimated:YES];
}


@end
